package com.gkd.controller.admin;


import com.gkd.pojo.dto.CommentDTO;
import com.gkd.pojo.dto.CommentPageQueryDTO;
import com.gkd.result.PageResult;
import com.gkd.result.Result;
import com.gkd.service.CommentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 评论相关接口
 */
@RestController
@CrossOrigin
@Slf4j
@RequestMapping("/admin/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    /**
     * 添加评论
     * @param commentDTO
     * @return
     */
    @PostMapping
    public Result add(@RequestBody CommentDTO commentDTO){
        log.info("添加评论:{}",commentDTO);
        commentService.add(commentDTO);
        return Result.success();
    }

    /**
     * 评论分页查询
     * @param commentPageQueryDTO
     * @return
     */
    @GetMapping
    public Result<PageResult> page(CommentPageQueryDTO commentPageQueryDTO){
        log.info("评论分页查询:{}",commentPageQueryDTO);
        PageResult pageResult=commentService.pageQuery(commentPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 评论删除
     * @param commentIds
     * @return
     */
    @DeleteMapping
    public Result delete(@RequestBody List<Integer> commentIds){
        log.info("删除评论:{}",commentIds);
        commentService.removeByIds(commentIds);
        return Result.success();
    }

    /**
     * 修改评论
     * @param commentDTO
     * @return
     */
    @PutMapping
    public Result update(@RequestBody CommentDTO commentDTO){
        log.info("修改评论");
        commentService.update(commentDTO);
        return Result.success();
    }
}
